package com.sugar.psych.assessment.module.business.controller.app.userpsychassessmentrecord;

import com.sugar.psych.assessment.framework.common.pojo.CommonResult;
import com.sugar.psych.assessment.framework.common.pojo.PageParam;
import com.sugar.psych.assessment.framework.common.pojo.PageResult;
import com.sugar.psych.assessment.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.psych.assessment.module.business.controller.app.userpsychassessmentrecord.vo.AppNeedAnswerRespVO;
import com.sugar.psych.assessment.module.business.controller.app.userpsychassessmentrecord.vo.AppUserPsychAssessmentRecordDetailRespVO;
import com.sugar.psych.assessment.module.business.controller.app.userpsychassessmentrecord.vo.AppUserPsychAssessmentRecordSimpleRespVO;
import com.sugar.psych.assessment.module.business.controller.app.userpsychassessmentrecord.vo.UserAnswerQuestionReqVO;
import com.sugar.psych.assessment.module.business.service.userpsychassessmentrecord.UserPsychAssessmentRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.sugar.psych.assessment.framework.common.pojo.CommonResult.successApp;

@Tag(name = "APP - 用户心理测评记录")
@RestController
@RequestMapping("/psych/user-psych-assessment-record")
@Validated
public class AppUserPsychAssessmentRecordController {

    @Resource
    private UserPsychAssessmentRecordService userPsychAssessmentRecordService;

    @PostMapping("/restart")
    @Operation(summary = "重新答题")
    public CommonResult<Long> restart() {
        return successApp(userPsychAssessmentRecordService.restart(SecurityFrameworkUtils.getLoginUserId()));
    }

    @PostMapping("/restart-unfinished")
    @Operation(summary = "重新答题（未完成）")
    public CommonResult<Long> restartUnfinished() {
        return successApp(userPsychAssessmentRecordService.restartUnfinished(SecurityFrameworkUtils.getLoginUserId()));
    }

    @PostMapping("/create")
    @Operation(summary = "首次测评")
    public CommonResult<Long> appUserCreate() {
        return successApp(userPsychAssessmentRecordService.appUserCreate(SecurityFrameworkUtils.getLoginUserId()));
    }

    @PutMapping("/answer")
    @Operation(summary = "回答问题")
    public CommonResult<Long> userAnswerQuestion(@Valid @RequestBody UserAnswerQuestionReqVO answerReqVO) {
        return successApp(userPsychAssessmentRecordService.userAnswerQuestion(answerReqVO, SecurityFrameworkUtils.getLoginUserId()));
    }

    @GetMapping("/get")
    @Operation(summary = "根据ID查详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppUserPsychAssessmentRecordDetailRespVO> appGetUserPsychAssessmentRecord(@RequestParam("id") Long id) {
        return successApp(userPsychAssessmentRecordService.appGetUserPsychAssessmentRecord(id, SecurityFrameworkUtils.getLoginUserId()));
    }

    @GetMapping("/page")
    @Operation(summary = "分页查")
    public CommonResult<PageResult<AppUserPsychAssessmentRecordSimpleRespVO>> appGetRecordPage(PageParam pageParam) {
        return successApp(userPsychAssessmentRecordService.appGetRecordPage(pageParam, SecurityFrameworkUtils.getLoginUserId()));
    }

    @GetMapping("/need-answer")
    @Operation(summary = "返回用户当前答题状态与是否首次答题")
    public CommonResult<AppNeedAnswerRespVO> needAnswer() {
        return successApp(userPsychAssessmentRecordService.needAnswer(SecurityFrameworkUtils.getLoginUserId()));
    }

}